define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'reportclock/index' + location.search,
                    add_url: 'reportclock/add',
                    adds_url: 'reportclock/adds',
                    edit_url: 'reportclock/edit',
                    del_url: '',
                    multi_url: 'reportclock/multi',
                    import_url: 'reportclock/import',
                    table: 'reportclock',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'admin_name', title: __('员工名称'), operate: false},
                        {field: 'clock_in', title: __('上班时间'), operate: false},
                        {field: 'clock_out', title: __('交班时间'), operate: false},
                        {field: 'total_price', title: __('总交易额'), operate: false},
                        {field: 'status', title: __('状态'), searchList: {10:__('未报班'),20:__('已报班')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons:[
                                {
                                    name:'show',//名称
                                    text:'查看单据',
                                    title:'查看单据',
                                    classname: 'btn btn-info bg-teal',
                                    // icon: 'fa fa-check',//图标 可在添加菜单规则处 搜索图标见示例图
                                    url: 'reportclock/edit',//接口地址 控制器名/方法名
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if(row.status == 100){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }
                                },{
                                
					            name: 'ajax',
						            text: __('对账'),
						            title: __('对账'),
						            classname: 'btn btn-xs btn-success btn-magic btn-ajax',
						            icon: 'fa fa-magic',
						            url: 'reportclock/print',
						            confirm: '确认对账吗',
						             visible: function (row) {
                                           // 自定义按钮 动态是否显示
                                            return true;
                                      },
						            success: function (data, ret) {
						                Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
						                //如果需要阻止成功提示，则必须使用return false;
						                //return false;
						            },
						            error: function (data, ret) {
						                console.log(data, ret);
						                Layer.alert(ret.msg);
						                return false;
						            }


                            }
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        cashier_shift_new: function () {
            $("#push").on("click",function(e){
                e.preventDefault();
                var form=$("form");
                Fast.api.ajax({
                    url: 'reportclock/do_csn',
                    data: form.serialize()
                }, function (data) {
                    Fast.api.close();
                    parent.Toastr.success('操作成功');
                    parent.$(".btn-refresh").trigger("click");
                    return true;
                });
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
